import { createApp } from 'vue'
import { createPinia } from 'pinia'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import piniaPersist from 'pinia-plugin-persist'
import userStore from '@/stores/store'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
const pinia = createPinia();
pinia.use(piniaPersist);
app.use(pinia);
router.beforeEach((to, from) => {
  const store = userStore();
  if(['startpage','login','signup'].includes(to.name)){
    //console.log('不跳转'); //debug
    return;
  }
  else if( store.getJWT != '' && [0,1,2,3].includes(store.getPermission)){ //token不为空
    //console.log('不跳转2'); //debug
    return;
  }
  else
    //console.log('跳转'); //debug
    return { name:'login' };
});
app.use(router);
app.mount('#app');
